<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="referrer" content="no-referrer" />
    <title>{$active.name}-参加报名</title>
    {include file='default/public/header'/}
    <style type="text/css">
        body,.weui-cell{ background: #f5f5f5;}
    </style>
</head>
<body >

<div class="page-group">
    <div class="page">
        <div class="content">
            <nav class="bar bar-tab" style="height:0;top: 0;">
                {include file='default/public/fixed'/}
            </nav>
            {include file='default/public/nav'/}
            <article class="weui-article">
                <section>
                    <form id="form1">

                        <div class="weui-cells weui-cells_form"  style="margin-top: 0;margin-bottom: 50px;">
                            {foreach $active.act_field as $vo}
                            {switch name="vo.type" }
                            {case value="images"}
                            <div class="weui-cell image-cell">
                                <div class="weui-cell__bd">
                                    <div class="weui-uploader">
                                        <div class="weui-uploader__hd">
                                            <div class="weui-uploader__title">{$vo.name}</div>
                                        </div>
                                        <div class="weui-uploader__bd">
                                            <ul class="weui-uploader__files" id="images" data-name="{$vo.name}">
                                                {if condition="$participant.images"}
                                                {foreach $participant.images as $vo}
                                                <li class="weui-uploader__file">
                                                    <img src="{$vo}" width="100%" height="100%"/>
                                                </li>
                                                {/foreach}
                                                {/if}
                                            </ul>
                                            {if condition="empty($participant) || $participant.status == 2"}
                                            <div id="container">
                                                <div class="weui-uploader__input-box" id="selectfiles"></div>
                                            </div>
                                            {/if}
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            {/case}
                            {case value="nickname"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="nickname" value="{$participant.nickname}" id="nickname"  data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="birthday"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="date" placeholder="{$vo.name}" name="birthday" value="{$participant.birthday}" id="birthday" data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="gender"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="gender"
                                           value="{if condition='$participant.gender == 1'}男{elseif condition='$participant.gender == 2'}女{else/}{/if}"
                                           data-values="{$participant.gender}"
                                           id="gender" data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="mobile"}
                            <div class="weui-cell" >
                                <div class="weui-cell__hd"><label class="weui-label">{$vo.name}</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" type="text" placeholder="{$vo.name}" name="mobile" value="{$participant.mobile}" id="mobile" data-name="{$vo.name}"/>
                                </div>
                                <div class="weui-cell__ft">

                                </div>
                            </div>
                            {/case}
                            {case value="xuanyan"}
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <textarea class="weui-textarea" placeholder="请输入{$vo.name}" name="xuanyan" rows="3"
                                              id="xuanyan" style="background: #f5f5f5;"  data-name="{$vo.name}">{$participant.xuanyan}</textarea>
                                </div>
                            </div>
                            {/case}
                            {default /}
                            {/switch}
                            {/foreach}
                            {if condition="$participant.status ==2 && $participant.no_pass_intro"}
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <textarea class="weui-textarea"  rows="3" readonly style="background: #f5f5f5;color:red;">未通过原因:{$participant.no_pass_intro}</textarea>
                                </div>
                            </div>
                            {/if}
                            {switch name="$participant.status"}
                            {case value="0"}
                            <div class="item">
                                <div class="detail-btn" style="background: #ababab;">待 审 核</div>
                            </div>
                            {/case}
                            {case value="1"}
                            <div class="item">
                                <div class="detail-btn" >已 报 名</div>
                            </div>
                            {/case}
                            {case value="2"}
                            <div class="item" style="background: #f5f5f5;">
                                <div class="form-btn" style="background: #ababab;">审 核 未 通 过</div>
                                <span style="font-size: 12px;color:#929292;">请重新上传照片后点击按钮再次报名</span>
                            </div>
                            {/case}
                            {default /}
                            <div class="item">
                                <!-- <div class="form-btn" style="background: {$active.theme_color};">报 名</div> -->
                                <div id="postfiles" class="form-btn" style="background: {$active.theme_color};">报 名2</div>
                                <input type="hidden" id ="test_s" >
                            </div>
                            {/switch}
                        </div>
                    </form>
                </section>
            </article>
        </div>
    </div>
</div>

{include file='default/public/js'/}
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> 


<script type="text/javascript">

    var birthday,nickname,mobile,xuanyan,gender;

    //初始化配置信息
    //$.showLoading();
    // $.ajax({
    //     type:"get",
    //     url:"http://touwgf.37984.net/index.php/index/wx/wx_ajax?callback=?",
    //     data:{"url":window.location.href},
    //     async:"true",
    //     dataType:"jsonp",
    //     success:function(result){


         //$.hideLoading();
         //=========
            wx.config({
                debug: false,
                appId: '{$wxconfig.appId}', 
                timestamp: '{$wxconfig.timestamp}', 
                nonceStr: '{$wxconfig.nonceStr}', 
                signature: '{$wxconfig.signature}',
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone',
                    'chooseImage',
                    'previewImage',
                    'uploadImage',
                    'getLocalImgData',
                    'startRecord',
                    'stopRecord',
                    'onVoiceRecordEnd',
                    'playVoice',
                    'pauseVoice',
                    'stopVoice',
                    'onVoicePlayEnd',
                    'uploadVoice',
                    'downloadImage'
                ]
            });
            var share_title = '{$active.share_info.title}';
            var share_desc = '{$active.share_info.intro}';
            var share_link = '{$active.share_info.url}/channel_id/{$channel}';
            var share_imgUrl = '{$active.share_info.img}';
            var share_type = '';
            var share_dataUrl = '';

            wx.ready(function () {
                // 分享到朋友圈
                wx.onMenuShareTimeline({ title: share_title, link: share_link, imgUrl: share_imgUrl });
                // 分享给朋友
                wx.onMenuShareAppMessage({ title: share_title, desc: share_desc, link: share_link, imgUrl: share_imgUrl, type: share_type, dataUrl: share_dataUrl });
                // 分享到QQ
                wx.onMenuShareQQ({ title: share_title, desc: share_desc, link: share_link, imgUrl: share_imgUrl });
                // 分享到腾讯微博
                wx.onMenuShareWeibo({ title: share_title, desc: share_desc, link: share_link, imgUrl: share_imgUrl });
                // 分享到QQ空间
                wx.onMenuShareQZone({ title: share_title, desc: share_desc, link: share_link, imgUrl: share_imgUrl });
            });
        //=========
       // }

   //});

    //图片多媒体id组
    //var images = [];

    // var images = {
    //       localId: [],
    //       serverId: []
    // };


    var localId;

    $('.form-btn').click(function(){

        if(CheckForm()){
          var images =  $('#test_s').val();
            $.ajax({

                url:'{:url("do_sign_up")}',
                type:'post',
                data:{'id':'{$id}','nickname':nickname,'mobile':mobile,'birthday':birthday,'xuanyan':xuanyan,'imgs':images,'gender':gender},
                dataType:'json',
                success:function(data){

                    if(data.code == 0){
                        location.href = '{:url("detail",["id"=>$id])}'
                    }else{
                        $("#test_s").val(data.message);
                        //$.alert(data.message);
                    }
                }
            });
        }
        return false;
    });

    $('.detail-btn').click(function(){
        location.href = '{:url("detail",["id"=>$id])}';
    });

    $("#gender").select({
        title: "选择性别",
        items: [
            {
                title: "男",
                value: 1
            },
            {
                title: "女",
                value: 2
            }
        ]
    });

    function CheckForm(){
        $('.weui-cell').removeClass('weui-cell_warn');
        $('.weui-cell__ft').html('');

        if(images.length == 0){

            // $.alert($('#images').attr('data-name')+'不能为空1');
            // $('.image-cell').addClass('weui-cell_warn');
            // return false;
            
            // $.alert($('#images').attr('data-name')+'不能为空1');
            // $('#test_s').val();
            // return false;
        }
        var $nickname = $('#nickname');
        if($nickname.length > 0 ){
            nickname = $nickname.val();
            if(nickname == ''){
                $.alert($nickname.attr('data-name')+'不能为空2');
                $nickname.parents('.weui-cell').addClass('weui-cell_warn');
                $nickname.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $birthday = $('#birthday');
        if($birthday.length > 0 ){
            birthday = $birthday.val();
            if(birthday == ''){
                $.alert($birthday.attr('data-name')+'不能为空3');
                $birthday.parents('.weui-cell').addClass('weui-cell_warn');
                $birthday.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $gender = $('#gender');
        if($gender.length > 0 ){
            gender = $gender.attr('data-values');
            if(gender == ''){
                $.alert($gender.attr('data-name')+'不能为空4');
                $gender.parents('.weui-cell').addClass('weui-cell_warn');
                $gender.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $mobile = $('#mobile');
        if($mobile.length > 0 ){
            mobile = $mobile.val();
            if(mobile == ''){
                $.alert($mobile.attr('data-name')+'不能为空5');
                $mobile.parents('.weui-cell').addClass('weui-cell_warn');
                $mobile.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;
            if(!myreg.test(mobile))
            {
                $.alert('请输入有效的手机号码！');
                $mobile.parents('.weui-cell').addClass('weui-cell_warn');
                $mobile.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        var $xuanyan = $('#xuanyan');
        if($xuanyan.length > 0 ){
            xuanyan = $xuanyan.val();
            if(xuanyan == ''){
                $.alert($xuanyan.attr('data-name')+'不能为空6');
                $xuanyan.parents('.weui-cell').addClass('weui-cell_warn');
                $xuanyan.parents('.weui-cell').find('.weui-cell__ft').append('<i class="weui-icon-warn"></i>');
                return false;
            }
        }

        return true;
    }

    var has_cover = 0 , is_tip = 0;
    $('.images_box').click(function(){




        // if(images.length != 0){
        //     $.confirm("是否重新上传作品", function() {
        //         has_cover = 0;
        //         is_tip = 0;
        //         images = [];
        //         $('#images').html('');
        //         set_image();
        //     }, function() {
        //         return false;
        //     });
        // }else{
        //     set_image();
        // }

    });

    function set_image(){

        wx.ready(function () {
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'],
                sourceType: ['album', 'camera'],
                success: function (res) {
                    var localIds = res.localIds; 

                    for (var i=0; i < localIds.length; i++)
                    {

                         $('#images').append('<li class="weui-uploader__file"><img src="'+localIds[i]+'" width="100%" height="100%"/></li>');
                        // wx.uploadImage({
                        //     localId:  localIds[i],
                        //     isShowProgressTips: 1,
                        //     success: function (res) {

                        //         images.push(res.serverId); // 返回图片的服务器端ID

                        //     }
                        // });
                    }
                }
            });
        });

        // wx.error(function(res){
        //     alert("wx.error"+res.errMsg);
        // });

    }

</script>
<script type="text/javascript" src="__PUBLIC__/ot/lib/plupload-2.1.2/js/plupload.full.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/ot/upload.js"></script>
</body>
</html>
